-- Music switchin for TRASHDOWN
--if it doesn't work i swear it'll be embarassing

local TARGET_MAP = "MAP40"
local MUSIC_LUMP = "TWLR"
local CHANGE_TIME = 210 * TICRATE

addHook("ThinkFrame", function()
    if G_BuildMapName(gamemap) ~= TARGET_MAP then return end
    if leveltime < CHANGE_TIME then return end

    for player in players.iterate do
        if not player or not player.valid then continue end

        local isHideSeek = (gametype == GT_HIDEANDSEEK)
        local isRunnerInHnS = isHideSeek and not (player.pflags & PF_TAGIT)

        -- if you're no runner in HS, you're fine bro dw
        if isRunnerInHnS then continue end

        -- Music check EVERY FUCKING FRAMES
        if player and player.valid and player.mo then
            if not player.music or player.music ~= MUSIC_LUMP then
                S_ChangeMusic(MUSIC_LUMP, true, player)
            end
        end
    end
end)